#-----------------------------------------------------------------------------
# Project:     Multi-Programmer Game Demo
# Name:        Paddle.py
# Purpose:     Controllable Paddle Object
# 
# Authors:     Chris Spooner, Chris La-Roo
# Main Author: Chris Spooner
#
# Created:     11/30/2012
# Copyright:   (c) Chris Spooner 2012
# Licence:     New BSD
#-----------------------------------------------------------------------------
import pygame, math, sys, random
#Put in ball class and some functionss form the Ion dirver game I made earlier.
class Paddle():
    def __init__(self, images, speed, screenSize, waitMax = 1000):
        self.surfaces = []
        for image in images:
            surf = pygame.image.load(image)
            surf = pygame.transform.scale(surf, (20,100))
            self.surfaces += [surf]
        self.frame = 0
        self.waitCount = 0
        self.waitMax = waitMax
        self.maxFrame = len(self.surfaces)-1
        self.surface = self.surfaces[self.frame]
        self.rect = self.surface.get_rect()
        self.radius = self.rect.width/2
        self.maxSpeed = speed
        self.speed = [0,0]
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        
    
    def direction(self, dir):
        if dir == "up":
            self.speed[1] = -self.maxSpeed
        elif dir == "stop up":
            self.speed[1] = 0
        elif dir == "down":
            self.speed[1] = self.maxSpeed
        elif dir == "stop down":
            self.speed[1] = 0
        elif dir == "left":
            self.speed[0] = -self.maxSpeed
        elif dir == "stop left":
            self.speed[0] = 0
        elif dir == "right":
            self.speed[0] = self.maxSpeed
        elif dir == "stop right":
            self.speed[0] = 0
        
    def move(self):
            self.rect = self.rect.move(self.speed)  
        
                
    def place(self, pt):
        self.rect.center = pt
        
    def animate(self):
        if self.frame < self.maxFrame:
            self.frame += 1
        else:
            self.frame = 0
            # self.living = False
        self.surface = self.surfaces[self.frame]

    def ballCollide(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
                if (self.rect.bottom > other.rect.top and 
                    self.rect.top < other.rect.bottom):
                        other.speed[1] = other.speed[1]*-1
                        other.speed[0] = other.speed[0]*-1
                    
    def wallCollide(self):
        if (self.rect.top < 0 
            or self.rect.bottom > self.screenHeight):
            self.speed[1] = self.speed[1] *-1             